/*
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
 *
 * Copyright (c) 2016 - 2021 CCBlueX
 *
 * LiquidBounce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * LiquidBounce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
 */

package net.ccbluex.liquidbounce.features.module.modules.exploit

import net.ccbluex.liquidbounce.config.NamedChoice
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.entity.exactPosition
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket

/**
 * Damage module
 *
 * Deals the specified amount of damage to yourself.
 */

object ModuleDamage : Module("Damage", Category.EXPLOIT, disableActivation = true) {

    private val mode by enumChoice("Mode", DamageModeEnum.NCP, DamageModeEnum.values())
    private val damage by int("Damage", 1, 0..20)

    override fun enable() {
        damage(mode)
    }

    /**
     * Damage client player
     */
    fun damage(mode: DamageModeEnum) = mode.run()

    enum class DamageModeEnum(override val choiceName: String, val run: () -> Unit) : NamedChoice {
        NCP(
            "NCP",
            {
                val (x, y, z) = player.exactPosition

                repeat(65 * damage) {
                    network.sendPacket(PlayerMoveC2SPacket.PositionAndOnGround(x, y + 0.049, z, false))
                    network.sendPacket(PlayerMoveC2SPacket.PositionAndOnGround(x, y, z, false))
                }
                network.sendPacket(PlayerMoveC2SPacket.PositionAndOnGround(x, y, z, true))
            }
        ),
        AAC(
            "AAC",
            {
                player.velocity.y = 5.0 * damage
            }
        )
    }

}
